﻿namespace NTLib.Pipe.Network.Targets
{
    using Pipe.Targets;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Pipe.Descriptors;
    using System.Threading;
    using Core.Attributes;
    using System.Collections.ObjectModel;
    using Descriptors;

    /// <summary>
    /// Create the NetworkTargetDesciption in function of the target
    /// </summary>
    [Guid("9912FCBC-5B81-418D-9D0A-8B7DFA7C6A2D")]
    public sealed class NetworkTargetProvider : ITargetProvider
    {
        #region Fields

        private static readonly ReadOnlyCollection<Type> s_typesManaged;

        #endregion

        #region Ctor

        /// <summary>
        /// Initializes the <see cref="NetworkTargetProvider"/> class.
        /// </summary>
        static NetworkTargetProvider()
        {
            s_typesManaged = new ReadOnlyCollection<Type>(new Type[] { typeof(Uri), typeof(NetworkTargetLocation) });
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="NetworkTargetProvider"/> class.
        /// </summary>
        public NetworkTargetProvider()
        {
            this.Id = Guid.NewGuid();
            this.IsEnabled = true;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets the unique identifier of the component.
        /// </summary>
        public Guid Id { get; }

        /// <summary>
        /// Gets the information type managed.
        /// The child type will be associate.
        /// This collection will be used to associate a provider to the information give.
        /// </summary>
        public IEnumerable<Type> InfoTypeManaged { get { return s_typesManaged; } }

        /// <summary>
        /// Gets a value indicating whether this instance is enabled.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is enabled; otherwise, <c>false</c>.
        /// </value>
        public bool IsEnabled { get; private set; }

        #endregion

        #region Methods

        /// <summary>
        /// Locates the asynchronous.
        /// </summary>
        /// <typeparam name="U"></typeparam>
        /// <param name="information">The information.</param>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public Task<IEnumerable<ITargetDescriptor>> LocateAsync<U>(U information, CancellationToken token = default(CancellationToken))
        {
            return Task.FromResult<IEnumerable<ITargetDescriptor>>(null);
        }

        /// <summary>
        /// Generates the description from URI.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <returns></returns>
        private ITargetDescriptor GenerateDescriptionFromUri(Uri uri)
        {
            // config if Uri == Tcp/Udp then connector == TcpConnector
            return null;
        }

        #endregion
    }
}
